﻿<!DOCTYPE html>

<html>
<head>
    <title>后台权限管理系统</title>
</head>
<body style="text-align: center; background: #F0F0F0; overflow: hidden;">
    <div id="pageloading" style="display: block;"></div>
    <div id="topmenu" class="l-topmenu">
        <div class="l-topmenu-logo">管理系统</div>
        <div class="l-topmenu-welcome">
            <span class="l-topmenu-username"></span>欢迎您  &nbsp; 
            [<a href="javascript:f_changepassword()">修改密码</a>] &nbsp; 

             [<a href="javascript:f_login()">切换用户</a>]
            [<a href="javascript:f_logout()">退出</a>] 
        </div>

    </div>
    <div id="mainbody" class="l-mainbody" style="width: 99.2%; margin: 0 auto; margin-top: 3px;">
        <div position="left" title="主要菜单" id="mainmenu"></div>
        <div position="center" id="framecenter">
            <div tabid="home" title="我的主页">
                @Html.Partial("Welcome")
            </div>
        </div>
    </div>
    <script type="text/javascript">
        //几个布局的对象
        var layout, tab, accordion;
        //tabid计数器，保证tabid不会重复
        var tabidcounter = 0;
        //窗口改变时的处理函数
        function f_heightChanged(options) {
            if (tab)
                tab.addHeight(options.diff);
            if (accordion && options.middleHeight - 24 > 0)
                accordion.setHeight(options.middleHeight - 24);
        }
        //增加tab项的函数
        function f_addTab(tabid, text, url) {
            if (!tab) return;
            if (!tabid) {
                tabidcounter++;
                tabid = "tabid" + tabidcounter;
            }
            tab.addTabItem({ tabid: tabid, text: text, url: url });
        }

        //登录
        function f_login() {
            location.href = "/Manage/UserLogin";
        }
        //退出
        function f_logout() {
            $.ligerDialog.confirm('您确定要退出么？', function (yes) {
                $.ajax({
                    url: '/Manage/Logout',
                    dataType: 'text',
                    type: 'post',
                    success: function () {
                        location.href = "/Manage/UserLogin";
                    },
                    error: function (message) {
                        iTools.showError(message);
                    }
                });
            });
        }
        //修改密码
        function f_changepassword() {
            $(document).bind('keydown.changepassword', function (e) {
                if (e.keyCode == 13) {
                    doChangePassword();
                }
            });

            if (!window.changePasswordWin) {
                var changePasswordPanle = $("<form></form>");
                changePasswordPanle.ligerForm({
                    fields: [
                        { display: '旧密码', name: 'OldPassword', type: 'password', validate: { maxlength: 50, required: true, messages: { required: '请输入密码' } } },
                        { display: '新密码', name: 'NewPassword', type: 'password', validate: { maxlength: 50, required: true, messages: { required: '请输入密码' } } },
                        { display: '确认密码', name: 'NewPassword2', type: 'password', validate: { maxlength: 50, required: true, equalTo: '#NewPassword', messages: { required: '请输入密码', equalTo: '两次密码输入不一致' } } }
                    ]
                });

                //验证
                jQuery.metadata.setType("attr", "validate");
                iTools.validate(changePasswordPanle);

                window.changePasswordWin = $.ligerDialog.open({
                    width: 400,
                    height: 190, top: 200,
                    isResize: true,
                    title: '用户修改密码',
                    target: changePasswordPanle,
                    buttons: [
                    {
                        text: '确定', onclick: function () {
                            doChangePassword();
                        }
                    },
                    {
                        text: '取消', onclick: function () {
                            window.changePasswordWin.hide();
                            $(document).unbind('keydown.changepassword');
                        }
                    }
                    ]
                });
            }
            else {
                window.changePasswordWin.show();
            }

            function doChangePassword() {
                var OldPassword = $("#OldPassword").val();
                var LoginPassword = $("#NewPassword").val();
                if (changePasswordPanle.valid()) {
                    $.ajax({
                        url: '/Manage/ChangePassword',
                        dataType: 'json',
                        type: 'post',
                        data: { OldPassword: OldPassword, NewPassword: LoginPassword },
                        success: function () {
                            iTools.showSuccess('密码修改成功');
                            window.changePasswordWin.hide();
                            $(document).unbind('keydown.changepassword');
                        },
                        error: function (message) {
                            iTools.showError(message);
                        }
                    });
                }
            }

        }
        $(document).ready(function () {
            //菜单初始化
            $("ul.menulist li").live('click', function () {
                var jitem = $(this);
                var tabid = jitem.attr("tabid");
                var url = jitem.attr("url");
                if (!url) return;
                if (!tabid) {
                    tabidcounter++;
                    tabid = "tabid" + tabidcounter;
                    jitem.attr("tabid", tabid);

                    //给url附加menuno
                    if (url.indexOf('?') > -1) url += "&";
                    else url += "?";
                    url += "MenuNo=" + jitem.attr("menuno");
                    jitem.attr("url", url);
                }
                f_addTab(tabid, $("span:first", jitem).html(), url);
            }).live('mouseover', function () {
                var jitem = $(this);
                jitem.addClass("over");
            }).live('mouseout', function () {
                var jitem = $(this);
                jitem.removeClass("over");
            });

            //布局初始化 
            //layout
            layout = $("#mainbody").ligerLayout({ height: '100%', heightDiff: -3, leftWidth: 140, onHeightChanged: f_heightChanged, minLeftWidth: 120 });
            var bodyHeight = $(".l-layout-center:first").height();
            //Tab
            tab = $("#framecenter").ligerTab({ height: bodyHeight, contextmenu: true });


            //预加载dialog的背景图片
            //LG.prevDkialogImage();

            var mainmenu = $("#mainmenu");

            $.getJSON('@Url.Content("~/Manage/GetMenus?rnd=")' + Math.random(), function (menus) {

                $(menus).each(function (i, menu) {
                    var item = $('<div title="' + menu.ModuleName + '"><ul class="menulist"></ul></div>');

                    $(menu.children).each(function (j, submenu) {
                        var subitem = $('<li><img/><span></span><div class="menuitem-l"></div><div class="menuitem-r"></div></li>');
                        subitem.attr({
                            url: submenu.ModuleLinkUrl,
                            menuno: submenu.ModuleController
                        });
                        $("img", subitem).attr("src", (submenu.ModuleIcon || submenu.icon));
                        $("span", subitem).html(submenu.ModuleName || submenu.text);

                        $("ul:first", item).append(subitem);
                    });
                    mainmenu.append(item);

                });

                //Accordion
                accordion = $("#mainmenu").ligerAccordion({ height: bodyHeight - 24, speed: null });

                $("#pageloading").hide();
            });

            $.ajax({
                url: '@Url.Content("~/Manage/GetCurrentUser")',
                success: function (user) {
                    // $(".l-topmenu-username").html(user.Title + "，");
                    $("#labelusername").html(user.Title + ",");
                    var now = new Date(), hour = now.getHours();
                    if (hour > 4 && hour < 6) { $("#labelwelcome").html("凌晨好！") }
                    else if (hour < 9) { $("#labelwelcome").html("早上好！") }
                    else if (hour < 12) { $("#labelwelcome").html("上午好！") }
                    else if (hour < 14) { $("#labelwelcome").html("中午好！") }
                    else if (hour < 17) { $("#labelwelcome").html("下午好！") }
                    else if (hour < 19) { $("#labelwelcome").html("傍晚好！") }
                    else if (hour < 22) { $("#labelwelcome").html("晚上好！") }
                    else { $("#labelwelcome").html("夜深了，注意休息！") }

                },
                error: function () {
                    $.ligerDialog.alert('用户信息加载失败', 'error');
                }
            });
        });
    </script>
</body>
</html>
